#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
using namespace std;
int n, m;
const int N = 110;
char a[N][N];
int st[N][N];
int ret;
int dx[] = { 1,-1,0,0,1,1,-1,-1 };
int dy[] = { 0,0,1,-1,1,-1,1,-1 };
void dfs(int i, int j)
{
    st[i][j] = 1;
    for (int k = 0; k < 8; k++)
    {
        int x = i + dx[k];
        int y = j + dy[k];
        if (a[x][y] == 'W' && st[x][y] == 0)
        {
            dfs(x, y);
        }
    }
}
int main()
{
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= m; j++)
        {
            cin >> a[i][j];
        }
    }
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= m; j++)
        {
            if (a[i][j] == 'W' && st[i][j] == 0)
            {
                ret++;
                dfs(i, j);
            }
        }
    }
    cout << ret << endl;
    return 0;
}